package com.lineage.server.command.executor;

import com.lineage.server.datatables.lock.AccountReading;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Account;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1Acc implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1Acc.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1Acc();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      if (pc == null)
        _log.warn("系统命令执行: " + cmdName + " 取回指定帐号资料:" + arg); 
      StringTokenizer st = new StringTokenizer(arg);
      String accname = st.nextToken();
      L1Account acc = AccountReading.get().getAccount(accname.toLowerCase());
      if (acc != null) {
        String ip = null;
        String mac = null;
        if (acc.get_ip() != null)
          ip = acc.get_ip(); 
        if (acc.get_mac() != null)
          mac = acc.get_mac(); 
        StringBuilder info = new StringBuilder();
        info.append("IP位置:" + ip);
        info.append(" MAC位置:" + mac);
        info.append(" 最后登入时间:" + acc.get_lastactive().toString());
        if (pc == null) {
          _log.warn(info.toString());
        } else {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, info.toString()));
        } 
        StringBuilder info2 = new StringBuilder();
        info2.append("密码:" + acc.get_password());
        info2.append(" 超级密码:" + acc.get_spw());
        info2.append(" 仓库密码:" + acc.get_warehouse());
        if (pc == null) {
          _log.warn(info2.toString());
        } else {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, info2.toString()));
        } 
      } else {
        String e = "指令异常: 没有该帐号(" + accname + ")!!";
        if (pc == null) {
          _log.warn(e);
        } else {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, e));
        } 
      } 
    } catch (Exception e2) {
      if (pc == null) {
        _log.error("错误的命令格式: " + getClass().getSimpleName());
      } else {
        _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
      } 
    } 
  }
}
